package com.example.android_little_game

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.widget.Button
import android.widget.EditText

class SecondActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        supportActionBar?.hide()
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_second)

        // 取出控件
        val etName   = findViewById<EditText>(R.id.et_name)
        val etId     = findViewById<EditText>(R.id.et_id)
        val etGender = findViewById<EditText>(R.id.et_gender)
        val etPhone  = findViewById<EditText>(R.id.et_phone)
        val btnSave  = findViewById<Button>(R.id.btn_save)

        // 把旧值填进去
        etName.setText(PlayerData.name)
        etId.setText(PlayerData.id)
        etGender.setText(PlayerData.gender)
        etPhone.setText(PlayerData.phone)

        // 保存 → 写回单例 → 关闭页面
        btnSave.setOnClickListener {
            PlayerData.name   = etName.text.toString().trim()
            PlayerData.id     = etId.text.toString().trim()
            PlayerData.gender = etGender.text.toString().trim()
            PlayerData.phone  = etPhone.text.toString().trim()
            finish()   // 回到 MainActivity
        }
    }
}